import { createI18n } from 'vue-i18n'
import store from '@/store'
import messages from '@/lang'

let language = store.state.language

if (language == "") {
  language = navigator.language
  language = language || navigator.userLanguage
  language = language || "zh-cn"
  language = language.toLowerCase();
  store.commit("setLang", language);
}

const i18n = createI18n({
  fallbackLocale: 'zh-cn',
  globalInjection: true,
  legacy: false,
  locale: language || "zh-cn",
  messages,
});

export default i18n;